package com.zcf.controller;

import com.zcf.dto.CategoryDto;
import com.zcf.dto.UpdateCategoryDto;
import com.zcf.pojo.Category;
import com.zcf.pojo.Result;
import com.zcf.service.CategoryService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author zcf
 */
@RestController
public class ArticleCategoryController {

    @Resource
    private CategoryService categoryService;

    @PostMapping("/category")
    public Result add(@RequestBody @Validated CategoryDto categoryDto) {
        return categoryService.add(categoryDto);
    }

    @GetMapping("/category")
    public Result list() {
        return categoryService.list();
    }


    @GetMapping("/category/detail")
    public Result<Category> detail(Integer id) {
        Category category = categoryService.findById(id);
        return Result.success(category);
    }

    @PutMapping("/category")
    public Result update(@RequestBody UpdateCategoryDto updateCategoryDto){
      return   categoryService.update(updateCategoryDto);
    }

    @DeleteMapping("/category")
    public Result delete(Integer id){
        return categoryService.delete(id);
    }
}
